import {reqSearchGoodsInfoData,} from '../../api'
const state = {
  goodsInfo: {},
};
const actions = {
  // 1. 获取搜索的商品信息
  async getSearchGoodsInfo({ commit }, searchParams) {
    const result = await reqSearchGoodsInfoData(searchParams);
    if (result.code === 200) {
      commit("SAVE_SEARCH_GOODS_INFO", result.data);
    } else {
      console.log(result.message);
    }
  },
};
const mutations = {
  // 1. 存储搜索到的商品
  SAVE_SEARCH_GOODS_INFO(state, goodsInfo) {
    state.goodsInfo = goodsInfo;
  },
};
const getters = {
  // 1. 商品列表数据
  goodsList(state) {
    return state.goodsInfo.goodsList;
  },
  // 2. 详细属性列表
  attrsList(state) {
    return state.goodsInfo.attrsList;
  },
  // 3. 品牌列表
  trademarkList(state) {
    return state.goodsInfo.trademarkList;
  },
  // 4. 商品的总数量
  total(state) {
    return state.goodsInfo.total;
  }
};

export default {
  namespaced: true, // 开启命名空间 区分不同的模块
  state,
  actions,
  mutations,
  getters,
};
